package com.ruoyi.user.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.user.service.IUserProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/products")
public class UserProductController {

    @Autowired
    private IUserProductService userProductService;

    @PreAuthorize("@ss.hasPermi('user:products:category:names')")
    @GetMapping("/categories/by-merchant/{merchantId}")
    public AjaxResult categoryNamesByMerchant(@PathVariable("merchantId") Long merchantId) {
        java.util.List<String> names = userProductService.listCategoryNamesByMerchant(merchantId);
        return AjaxResult.success(names);
    }

    @PreAuthorize("@ss.hasPermi('user:products:list')")
    @GetMapping("/by-merchant/{merchantId}")
    public AjaxResult productsByMerchant(@PathVariable("merchantId") Long merchantId) {
        java.util.List<com.ruoyi.user.domain.MerchantProduct> list = userProductService.listProductsByMerchant(merchantId);
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('user:products:specs')")
    @GetMapping("/{productId}/specs")
    public AjaxResult productSpecs(@PathVariable("productId") Long productId) {
        com.ruoyi.user.domain.vo.ProductDetails vo = userProductService.getProductSpecs(productId);
        return AjaxResult.success(vo);
    }
}
